package logic;

import java.util.Iterator;
import java.util.List;

import data.IDestinationDAO;
import data.JDBCDestinationDAO;

public class DestinationList {
	
	IDestinationDAO d = new JDBCDestinationDAO();
	private static DestinationList destList;
	private List<Destination> ld;
	
	public static synchronized DestinationList getInstance(){
		if(destList == null){
			destList = new DestinationList();
		}
		return destList;
	}
	
	private DestinationList(){
		ld = (new JDBCDestinationDAO()).selectAll();
	}
	
    public List<Destination> getDestinations() {
        return ld;
    }

    public Destination getDestination(String destId) {
        Destination result = null;
        for (Iterator<Destination> iter = ld.iterator(); iter.hasNext();) {
            Destination d = (Destination) iter.next();
            if (d.getId().equals(destId)) {
                result = d;
            }
        }
        return result;
    }

	public List<Destination> getMostPopularDestinies(){
		
		return d.selectMostPopularDestinies();
	}
}
